package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {
    @Select(" select count(*) from dish,category where dish.category_id=category.id and category.id=#{id};")
    Long count(Long id);
    @AutoFill(OperationType.INSERT)
    void save(Dish dish);

    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);
    @Select("select d.*,c.name as categoryName from dish d" +
            " left outer join category c on d.category_id=c.id where d.id=#{id}")
    DishVO getById(Long id);
    void delete(List<Long> ids);

    List<Dish> select(List<Long> ids);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    @Select("select* from dish where category_id=#{id}")
    List<Dish> getByTypeId(Integer id);

    /**
     * 在Setmeal里面计算是否有停售菜品
     * @param id
     * @return
     */
    @Select("select count(*) from dish,setmeal_dish,setmeal " +
            "where dish.status=0 " +
            "  and setmeal.id=52 " +
            " and setmeal_dish.setmeal_id=setmeal.id and " +
            " dish.id=setmeal_dish.dish_id;")
    Long countStatus(Long id);

    /**
     * 导入时用到，在DishServiceimpl商品浏览中使用
     * @param dish
     * @return
     */
    @Select("select* from dish where status=#{status} and category_id=#{categoryId}")
    List<Dish> list(Dish dish);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
